﻿Shader "Hidden/Skinn/LightMapAtlas"
{
	Properties
	{
		[Toggle] _UseColor("Use Color", Float) = 0
		_Color("Color", Color) = (1, 1, 1, 1)

		_MainTex("Render Texture", 2D) = "white" {}

		[Toggle] _ConvertBumpMap("Normal Map", Float) = 0
		[Toggle] _ToggleUV("Toggle Surface UV", Float) = 0
	}
		SubShader
		{

		//Tags{"Queue" = "AlphaTest" "RenderType" = "TransparentCutout"}

		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off

			//AlphaToMask On

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag 
			#include "UnityCG.cginc"

			float _UseColor;
			float4 _Color;
			sampler2D _MainTex;
			float _ConvertBumpMap;
			float _ToggleUV;

			struct v2f
			{
				float4 pos : SV_POSITION;
				float4 bakedValue : TEXCOORD0;
				float2 uv : TEXCOORD1;
			};

			v2f vert(appdata_full v)
			{
				v2f o;
				UNITY_INITIALIZE_OUTPUT(v2f,o);

				float2 surface = (_ToggleUV == 0 ? v.texcoord1.xy : v.texcoord.xy);

				//surface.x = frac(surface.x / 1) * 1;
				//surface.y = frac(surface.y / 1) * 1;

				o.pos = float4 ((surface * 2) - 1, 1, 1);
				o.pos.y = -o.pos.y;

				float2 uv = v.texcoord;
				//uv.x = fmod(uv.x, 1);
				//uv.y = fmod(uv.y, 1);
				o.uv = uv;
				return o;
			}

			half4 frag(v2f i) : COLOR
			{
				half4 color = tex2D(_MainTex, i.uv).rgba;
				half4 finalColor = color;
				if (_ConvertBumpMap > 0)
				{
					//finalColor.rgb = UnpackNormal(tex2D(_MainTex, i.uv));
					finalColor.r = 0.5;
					finalColor.g = color.g;
					finalColor.b = color.r;
					finalColor.a = color.a;
				}
				else if (_UseColor > 0)
				{
					finalColor *= _Color;
					finalColor.a = clamp(finalColor.a, 1e-12, 1);
				}

				return finalColor;
			}

			ENDCG
		}
	}
	FallBack "Diffuse"
}